package com.sa.user.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sa.user.api.dto.PermissionDTO;
import com.sa.user.dataobject.Permission;
import com.sa.user.mapper.PermissionMapper;
import com.sa.user.msmapper.MsPermissionMapper;
import com.sa.user.service.PermissionService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permission>
    implements PermissionService{

    private final MsPermissionMapper msPermissionMapper;
    private final PermissionMapper permissionMapper;

    @Override
    public List<PermissionDTO> loadPermissionsByRoleId(Integer roleId) {
        List<Permission> permissions = permissionMapper.loadPermissionsByRoleId(roleId);
        if (permissions != null && !permissions.isEmpty()) {
            return permissions.stream().map(permission -> {
                return msPermissionMapper.toDTO(permission);
            }).toList();
        }
        return null;
    }
}




